//
// Created by syj on 2024/3/14.
//

#ifndef TRANSMIDDLE_COMMON_H
#define TRANSMIDDLE_COMMON_H

#include <iostream>
#include <memory>
#include <string>
#include <type_traits>

#include <spdlog/common.h>
#include <spdlog/details/log_msg.h>

#include "middle/core/types.h"

namespace log{
    /** 日志模式，可以组合 */
    enum class LogMode : uint8_t {
        kRemote = 0x01U,
        kFile = 0x02U,
        kConsole = 0x04U,
        kNone = 0x00U,
    };
    SUPPORT_ENUM_AS_FLAG(LogMode)

    /** 日志等级 */
    using LogLevel = spdlog::level::level_enum;

    /** 配置文件中键值 */
    const char *const KEY_LOG = "log";
    const char *const KEY_LOG_ID = "logid";
    const char *const KEY_LOG_LEVEL = "loglevel";
    const char *const KEY_LOG_MODE = "logmode";
    const char *const KEY_LOG_DIR = "logdir";
    const char *const KEY_LOG_FILE = "logfile";
    const char *const KEY_FILE_SIZE = "filesize";
    const char *const KEY_FILE_NUM = "filenum";
    const char *const KEY_FUSH_INTERVAL = "interval";


    /** 日志模式字符串*/
    const char *const kLogModeConsole = "console";
    const char *const kLogModeFile = "file";
    const char *const kLogModeRemote = "remote";
    const char *const kLogModeNone = "none";

    /** 从字符串转换为日志模式 */
    inline LogMode StringToMode(std::string const &str) {
        if (str == kLogModeRemote) {
            return LogMode::kRemote;
        } else if (str == kLogModeFile) {
            return LogMode::kFile;
        } else if (str == kLogModeConsole) {
            return LogMode::kConsole;
        } else {
            return LogMode::kNone;
        }
    }

    /** 日志模式转字符串 */
    inline const char *ModeToString(LogMode &mode) {
        switch (mode) {
            case LogMode::kConsole:
                return kLogModeConsole;
            case LogMode::kFile:
                return kLogModeFile;
            case LogMode::kRemote:
                return kLogModeRemote;
            default:
                return kLogModeNone;
        }
    }

}  // namespace log

//namespace core {
//
//    template<>
//    inline std::string stringify<mos::log::LogLevel>(
//            mos::log::LogLevel const &value) {
//        auto level_string_views = spdlog::level::to_string_view(value);
//        return std::string(level_string_views.data(), level_string_views.size());
//    }
//
//    template<>
//    inline mos::log::LogLevel parse(std::string const &value) {
//        return spdlog::level::from_str(value);
//    }
//}

#endif //TRANSMIDDLE_COMMON_H
